package org.hackystat.devcathlon.ui.page.profile;

import static org.junit.Assert.*;

import org.apache.wicket.util.tester.FormTester;
import org.apache.wicket.util.tester.WicketTester;
import org.hackystat.devcathlon.configuration.ConfigurationException;
import org.hackystat.devcathlon.engine.profile.Profile;
import org.hackystat.devcathlon.engine.test.DevcathlonTestHelper;
import org.hackystat.devcathlon.ui.DevcathlonApplication;
import org.hackystat.devcathlon.ui.DevcathlonSession;
import org.junit.Before;
import org.junit.Test;

/**
 * Test Profile Session.
 * @author Anthony Du
 *
 */
public class TestProfileSession extends DevcathlonTestHelper {
  /**
   * Setup Profile session.
   * 
   * @throws ConfigurationException Unexpected error. 
   */
  @Before
  public void setUp() throws ConfigurationException {
    WicketTester tester = new WicketTester(new DevcathlonApplication());
    tester.startPage(ProfilePage.class);
    
    FormTester formTester = tester.newFormTester("loginForm");
    formTester.setValue("user", "admin@hackystat.org");
    formTester.setValue("password", "admin@hackystat.org");
    formTester.submit();
    
    tester.assertRenderedPage(ProfilePage.class);
  }
  
  /**
   * Test Profile Session.
   * 
   * @throws ConfigurationException Unexpected error. 
   */
  @Test
  public void testProfileSession() throws ConfigurationException {
    ProfileSession profileSession = DevcathlonSession.get().getProfileSession();
    Profile profile = profileSession.getProfile();
    assertNotNull("profile not null", profile);
    profileSession.setBio(profile.getBioInfo());
    profileSession.setFirstName(profile.getFirstName());
    profileSession.setLastName(profile.getLastName());
    profileSession.setGender(profile.getGender());
    profileSession.setLocation(profile.getLocation());
    profileSession.setContact(profile.getContact());
    profileSession.setScreenName(profile.getScreenName());
    assertNotNull("profile bio not null", profileSession.getBio());
    assertTrue("teams list is empty", profileSession.getTeams().isEmpty());
    assertNotNull("user null", profileSession.getProfile().getEmailAddresses());
  }
}
